<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
    <title>Majestic Admin</title>
    <link href="../../vendors/mdi/css/materialdesignicons.min.css" rel="stylesheet">
    <link href="../../vendors/base/vendor.bundle.base.css" rel="stylesheet">
    <link href="../../css/style.css" rel="stylesheet">
    <link href="../../images/favicon.png" rel="shortcut icon"/>
    <style>
        .listBox {
            min-height: 120px;
        }
    </style>
</head>

<body>
<div class="container-scroller">
    <nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
        <div class="navbar-brand-wrapper d-flex justify-content-center">
            <div class="navbar-brand-inner-wrapper d-flex justify-content-between align-items-center w-100">
                <a class="navbar-brand brand-logo" href="../../index.html"><img alt="logo"
                                                                                src="../../images/logo.svg"/></a>
                <a class="navbar-brand brand-logo-mini" href="../../index.html"><img
                        alt="logo" src="../../images/logo-mini.svg"/></a>
                <button class="navbar-toggler navbar-toggler align-self-center" data-toggle="minimize"
                        type="button">
                    <span class="mdi mdi-sort-variant"></span>
                </button>
            </div>
        </div>
        <div class="navbar-menu-wrapper d-flex align-items-center justify-content-end">
            <ul class="navbar-nav mr-lg-4 w-100">
                <li class="nav-item nav-search d-none d-lg-block w-100">
                    <div class="input-group">
                        <div class="input-group-prepend">
                                <span id="search" class="input-group-text">
                                    <i class="mdi mdi-magnify"></i>
                                </span>
                        </div>
                        <input aria-describedby="search" aria-label="search" class="form-control"
                               placeholder="Search now"
                               type="text">
                    </div>
                </li>
            </ul>
            <ul class="navbar-nav navbar-nav-right">
                <li class="nav-item dropdown me-1">
                    <a id="messageDropdown"
                       class="nav-link count-indicator dropdown-toggle d-flex justify-content-center align-items-center"
                       data-bs-toggle="dropdown" href="#">
                        <i class="mdi mdi-message-text mx-0"></i>
                        <span class="count"></span>
                    </a>
                    <div aria-labelledby="messageDropdown"
                         class="dropdown-menu dropdown-menu-right navbar-dropdown">
                        <p class="mb-0 font-weight-normal float-left dropdown-header">Messages</p>
                        <a class="dropdown-item">
                            <div class="item-thumbnail">
                                <img alt="image" class="profile-pic" src="../../images/faces/face4.jpg">
                            </div>
                            <div class="item-content flex-grow">
                                <h6 class="ellipsis font-weight-normal">David Grey
                                </h6>
                                <p class="font-weight-light small-text text-muted mb-0">
                                    The meeting is cancelled
                                </p>
                            </div>
                        </a>
                        <a class="dropdown-item">
                            <div class="item-thumbnail">
                                <img alt="image" class="profile-pic" src="../../images/faces/face2.jpg">
                            </div>
                            <div class="item-content flex-grow">
                                <h6 class="ellipsis font-weight-normal">Tim Cook
                                </h6>
                                <p class="font-weight-light small-text text-muted mb-0">
                                    New product launch
                                </p>
                            </div>
                        </a>
                        <a class="dropdown-item">
                            <div class="item-thumbnail">
                                <img alt="image" class="profile-pic" src="../../images/faces/face3.jpg">
                            </div>
                            <div class="item-content flex-grow">
                                <h6 class="ellipsis font-weight-normal"> Johnson
                                </h6>
                                <p class="font-weight-light small-text text-muted mb-0">
                                    Upcoming board meeting
                                </p>
                            </div>
                        </a>
                    </div>
                </li>
                <li class="nav-item dropdown me-4">
                    <a id="notificationDropdown"
                       class="nav-link count-indicator dropdown-toggle d-flex align-items-center justify-content-center notification-dropdown"
                       data-bs-toggle="dropdown" href="#">
                        <i class="mdi mdi-bell mx-0"></i>
                        <span class="count"></span>
                    </a>
                    <div aria-labelledby="notificationDropdown"
                         class="dropdown-menu dropdown-menu-right navbar-dropdown">
                        <p class="mb-0 font-weight-normal float-left dropdown-header">Notifications</p>
                        <a class="dropdown-item">
                            <div class="item-thumbnail">
                                <div class="item-icon bg-success">
                                    <i class="mdi mdi-information mx-0"></i>
                                </div>
                            </div>
                            <div class="item-content">
                                <h6 class="font-weight-normal">Application Error</h6>
                                <p class="font-weight-light small-text mb-0 text-muted">
                                    Just now
                                </p>
                            </div>
                        </a>
                        <a class="dropdown-item">
                            <div class="item-thumbnail">
                                <div class="item-icon bg-warning">
                                    <i class="mdi mdi-settings mx-0"></i>
                                </div>
                            </div>
                            <div class="item-content">
                                <h6 class="font-weight-normal">Settings</h6>
                                <p class="font-weight-light small-text mb-0 text-muted">
                                    Private message
                                </p>
                            </div>
                        </a>
                        <a class="dropdown-item">
                            <div class="item-thumbnail">
                                <div class="item-icon bg-info">
                                    <i class="mdi mdi-account-box mx-0"></i>
                                </div>
                            </div>
                            <div class="item-content">
                                <h6 class="font-weight-normal">New user registration</h6>
                                <p class="font-weight-light small-text mb-0 text-muted">
                                    2 days ago
                                </p>
                            </div>
                        </a>
                    </div>
                </li>
                <li class="nav-item nav-profile dropdown">
                    <a id="profileDropdown" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#">
                        <img alt="profile" src="../../images/faces/face5.jpg"/>
                        <span class="nav-profile-name">Louis Barnett</span>
                    </a>
                    <div aria-labelledby="profileDropdown"
                         class="dropdown-menu dropdown-menu-right navbar-dropdown">
                        <a class="dropdown-item">
                            <i class="mdi mdi-settings text-primary"></i>
                            Settings
                        </a>
                        <a class="dropdown-item">
                            <i class="mdi mdi-logout text-primary"></i>
                            Logout
                        </a>
                    </div>
                </li>
            </ul>
            <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" data-toggle="offcanvas"
                    type="button">
                <span class="mdi mdi-menu"></span>
            </button>
        </div>
    </nav>
    <div class="container-fluid page-body-wrapper">
        <nav id="sidebar" class="sidebar sidebar-offcanvas">
            <ul class="nav">
                <li class="nav-item">
                    <a class="nav-link" href="index.html">
                        <i class="mdi mdi-home menu-icon"></i>
                        <span class="menu-title">仪表盘</span>
                    </a>
                </li>

                <li class="nav-item">
                    <a aria-controls="ui-store" aria-expanded="false" class="nav-link" data-bs-toggle="collapse"
                       href="#ui-store">
                        <i class="mdi mdi-circle-outline menu-icon"></i>
                        <span class="menu-title">门店基本信息</span>
                        <i class="menu-arrow"></i>
                    </a>
                    <div id="ui-store" class="collapse">
                        <ul class="nav flex-column sub-menu">
                            <li class="nav-item">
                                <a class="nav-link" href="../store/store.html">门店管理</a></li>
                            <li class="nav-item">
                                <a class="nav-link" href="../store/device.html">设备管理</a></li>
                            <li class="nav-item">
                                <a class="nav-link" href="../store/storeCode.html">二维码管理</a></li>
                        </ul>
                    </div>
                </li>
                <li class="nav-item">
                    <a aria-controls="ui-basic" aria-expanded="false" class="nav-link" data-bs-toggle="collapse"
                       href="#ui-basic">
                        <i class="mdi mdi-circle-outline menu-icon"></i>
                        <span class="menu-title">员工管理</span>
                        <i class="menu-arrow"></i>
                    </a>
                    <div id="ui-basic" class="collapse">
                        <ul class="nav flex-column sub-menu">
                            <li class="nav-item"><a class="nav-link"
                                                    href="pages/ui-features/buttons.html">Buttons</a></li>
                            <li class="nav-item"><a class="nav-link"
                                                    href="pages/ui-features/typography.html">Typography</a></li>
                        </ul>
                    </div>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="pages/charts/chartjs.html">
                        <i class="mdi mdi-chart-pie menu-icon"></i>
                        <span class="menu-title">会员管理</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="pages/tables/basic-table.html">
                        <i class="mdi mdi-grid-large menu-icon"></i>
                        <span class="menu-title">预约管理</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="pages/icons/mdi.html">
                        <i class="mdi mdi-emoticon menu-icon"></i>
                        <span class="menu-title">调理管理</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a aria-controls="auth" aria-expanded="false" class="nav-link" data-bs-toggle="collapse"
                       href="#auth">
                        <i class="mdi mdi-account menu-icon"></i>
                        <span class="menu-title">收费管理</span>
                        <i class="menu-arrow"></i>
                    </a>
                    <div id="auth" class="collapse">
                        <ul class="nav flex-column sub-menu">
                            <li class="nav-item"><a class="nav-link" href="pages/samples/login.html"> Login </a>
                            </li>
                            <li class="nav-item"><a class="nav-link" href="pages/samples/login-2.html"> Login 2
                            </a></li>
                            <li class="nav-item"><a class="nav-link" href="pages/samples/register.html"> Register
                            </a></li>
                            <li class="nav-item"><a class="nav-link" href="pages/samples/register-2.html"> Register
                                2 </a></li>
                            <li class="nav-item"><a class="nav-link" href="pages/samples/lock-screen.html">
                                Lockscreen </a></li>
                        </ul>
                    </div>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="documentation/documentation.html">
                        <i class="mdi mdi-file-document-box-outline menu-icon"></i>
                        <span class="menu-title">财务统计</span>
                    </a>
                </li>
            </ul>
        </nav>
        <!-- partial -->
        <div class="main-panel">
            <div class="content-wrapper">

                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-2">
                                    <div class="form-group d-flex">
                                        <label class=" col-form-label form-control-sm">部门</label>
                                        <div class="">
                                            <input class="form-control form-control-sm" placeholder="请选择部门"
                                                   type="text"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-2">
                                    <div class="form-group d-flex">
                                        <label class=" col-form-label form-control-sm">员工</label>
                                        <div class="">
                                            <input class="form-control form-control-sm" placeholder="请输入员工姓名"
                                                   type="text"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-2">
                                    <div class="form-group d-flex">
                                        <label class="col-form-label form-control-sm">预约时间</label>
                                        <div class="">
                                            <input class="form-control form-control-sm" type="date"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-3 ">
                                    <button class="btn btn-primary btn-sm text-white"
                                            style="padding-left: 2rem;padding-right: 2rem">确认
                                    </button>
                                </div>
                            </div>
                            <div class="card">
                                <div class="card-body">
                                    <div class="card-title">上午排班表</div>
                                    <div>
                                        <div id="morningBox" class="row gap-5 row-cols-6 text-center">
                                        </div>
                                    </div>
                                </div>

                            </div>
                            <div class="card mt-2">
                                <div class="card-body">
                                    <div class="card-title">下午排班表</div>
                                    <div>
                                        <div id="afternoonBox" class="row gap-5 row-cols-6 text-center">
                                        </div>
                                    </div>
                                </div>

                            </div>
                            <div id="myModal" class="modal">
                                <div class="modal-dialog">
                                    <div class="modal-content">

                                        <!-- 模态框头部 -->
                                        <div class="modal-header">
                                            <h4 class="modal-title">添加预约</h4>
                                            <button class="btn-close" data-bs-dismiss="modal" type="button"></button>
                                        </div>

                                        <!-- 模态框内容 -->
                                        <div class="modal-body">
                                            <form action="">
                                                <div class="mb-3 mt-3">
                                                    <label class="form-label" for="text">姓名:</label>
                                                    <input id="email" class="form-control" name="email"
                                                           placeholder="请输入姓名" type="email">
                                                </div>
                                                <div class="mb-3">
                                                    <label class="form-label" for="pwd">手机号:</label>
                                                    <input id="pwd" class="form-control" name="pswd"
                                                           placeholder="请输入手机号" type="password">
                                                </div>
                                                <div class="mb-3">
                                                    <label class="form-label" for="pwd">预约项目:</label>
                                                    <select id="sel1" class="form-select" name="sellist1">
                                                        <option>预约项目</option>
                                                        <option>2</option>
                                                        <option>3</option>
                                                        <option>4</option>
                                                    </select>
                                                </div>

                                            </form>
                                        </div>

                                        <!-- 模态框底部 -->
                                        <div class="modal-footer">
                                            <button class="btn btn-primary text-white" data-bs-dismiss="modal"
                                                    type="button">确认
                                            </button>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <footer class="footer">
                <div class="d-sm-flex justify-content-center justify-content-sm-between">
                        <span class="text-muted text-center text-sm-left d-block d-sm-inline-block">Copyright © <a
                                href="https://www.bootstrapdash.com/" target="_blank">bootstrapdash.com </a>2021</span>
                    <span class="float-none float-sm-right d-block mt-1 mt-sm-0 text-center">Only the best <a
                            href="https://www.bootstrapdash.com/" target="_blank"> Bootstrap dashboard </a>
                            templates</span>
                </div>
            </footer>
        </div>
    </div>
</div>

<script src="../../vendors/base/vendor.bundle.base.js"></script>
<script src="../../js/off-canvas.js"></script>
<script src="../../js/hoverable-collapse.js"></script>
<script src="../../js/template.js"></script>
<script src="../../js/file-upload.js"></script>
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script>

</script>
<script>
    var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
    var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
        return new bootstrap.Tooltip(tooltipTriggerEl)
    })

    /**
     * 根据排班时间生成数据
     * startTime number 排班开始时间(毫秒数)
     * endTime number  排班结束时间(毫秒数)
     * gapTime number 间隔时间
     * bookableNumber number 每个间隔可预约人数
     * dataTime return 返回值排班数组 [{start: '09:00', end: '09:20', isCheck: true, numbers: 0}]
     * */
    function generateData(startTime, endTime, gapTime, bookableNumber) {
        const start = startTime;
        const end = endTime;
        let currentTime = start;
        const dataTime = [];
        while (currentTime <= end) {
            dataTime.push({
                // 开始时间
                start: dayjs(currentTime).format('HH:mm'),
                // 结束时间
                end: dayjs(currentTime + gapTime * 60 * 1000).format('HH:mm'),
                isCheck: null,
                // 可预约人数
                numbers: bookableNumber,
                // 预约人信息
                appointDatas: []
            });
            currentTime = currentTime + gapTime * 60 * 1000; // 间隔时间
        }
        return dataTime;
    }

    // 某个员工上午值班数据
    const morning = generateData(1698195600000, 1698206400000, 20, 2);
    // 某个员工下午值班数据
    const afternoon = generateData(1698210000000, 1698228000000, 20, 2);
    console.log(
        '某个员工上午值班数据:', morning
    )
    console.log(
        '某个员工上午值班数据:', afternoon
    )
    // 模拟接口返回数据
    const datas = {
        morningDta: [
            {
                name: '赵又廷',
                startTime: '09:00',
                project: '针灸'
            },
            {
                name: '高圆圆',
                startTime: '09:00',
                project: '艾草'
            },
            {
                name: '胡歌',
                startTime: '09:20',
                project: '艾草'
            }
        ],
        afternoonData: [
            {
                name: '周杰伦',
                startTime: '16:20',
                project: '艾草'
            },
            {
                name: '甄子丹',
                startTime: '16:20',
                project: '艾草'
            }
        ]
    }
    // 处理上午数据
    datas.morningDta.forEach(item => {
        morning.forEach(items => {
            if (item.startTime === items.start) {
                items.isCheck = true
                items.numbers -= 1
                items.appointDatas.push(item)
            }
        })
    })
    // 处理下午数据
    datas.afternoonData.forEach(item => {
        afternoon.forEach(items => {
            if (item.startTime === items.start) {
                items.isCheck = true
                items.numbers -= 1
                items.appointDatas.push(item)
            }
        })
    })
    //  获取上午排班元素
    const morningBox = document.getElementById('morningBox')
    // 获取下午排班元素
    const afternoonBox = document.getElementById('afternoonBox')
    // 根据数据动态生成数据
    morning.forEach((item, index) => {
        let element = document.createElement('div')
        if (item.numbers === 0) {
            element.className = "col bg-danger  text-white hover-cursor listBox"
            element.innerHTML = `
             <div class="col bg-danger p-3 text-white hover-cursor ceshi"  data-bs-toggle="tooltip" title="点击查看具体内容">
               ${item.start + '-' + item.end + '(预约已满)'}
               <ul class="list-group list-group-flush yy-lIST ">
               </ul>
            </div>
            `
            if (item.appointDatas.length > 0) {
                const listGroup = element.getElementsByClassName('yy-lIST')[0]
                item.appointDatas.forEach((appItem, appIndex) => {
                    let listGroupItem = document.createElement('li')
                    listGroupItem.className = 'list-group-item bg-transparent text-start text-white'
                    listGroupItem.innerText = appItem.name + '*' + appItem.project

                    listGroup.appendChild(listGroupItem)
                })

            }

        } else {
            element.className = "col bg-primary  text-white hover-cursor listBox"
            element.innerHTML = `
             <div class="col bg-primary  p-3  text-white hover-cursor appoint" data-time="morning" data-index="${index}" data-bs-toggle="modal" data-bs-target="#myModal">
               ${item.start + '-' + item.end + `(可预约${item.numbers}人)`}
               <ul class="list-group list-group-flush yy-lIST">
               </ul>
            </div>
            `
            if (item.appointDatas.length > 0) {
                const listGroup = element.getElementsByClassName('yy-lIST')[0]
                item.appointDatas.forEach((appItem, appIndex) => {
                    let listGroupItem = document.createElement('li')
                    listGroupItem.className = 'list-group-item bg-transparent text-start text-white'
                    listGroupItem.innerText = appItem.name + '*' + appItem.project
                    listGroup.appendChild(listGroupItem)
                })

            }
        }
        morningBox.appendChild(element)
    })
    afternoon.forEach((item, index) => {
        let element = document.createElement('div')
        if (item.numbers === 0) {
            element.className = "col bg-danger  text-white hover-cursor listBox"
            element.innerHTML = `
             <div class="col bg-danger p-3 text-white hover-cursor ceshi">
               ${item.start + '-' + item.end + '(预约已满)'}
               <ul class="list-group list-group-flush yy-lIST ">
               </ul>
            </div>
            `
            if (item.appointDatas.length > 0) {
                const listGroup = element.getElementsByClassName('yy-lIST')[0]
                item.appointDatas.forEach((appItem, appIndex) => {
                    let listGroupItem = document.createElement('li')
                    listGroupItem.className = 'list-group-item bg-transparent text-start text-white'
                    listGroupItem.innerText = appItem.name + '*' + appItem.project
                    listGroupItem.setAttribute('data-bs-toggle', 'tooltip')
                    listGroupItem.setAttribute('title', '点击查看具体内容')
                    listGroup.appendChild(listGroupItem)
                })

            }

        } else {
            element.className = "col bg-primary  text-white hover-cursor listBox"
            element.innerHTML = `
             <div class="col bg-primary  p-3  text-white hover-cursor appoint" data-time="morning" data-index="${index}" data-bs-toggle="modal" data-bs-target="#myModal">
               ${item.start + '-' + item.end + `(可预约${item.numbers}人)`}
               <ul class="list-group list-group-flush yy-lIST">
               </ul>
            </div>
            `
            if (item.appointDatas.length > 0) {
                const listGroup = element.getElementsByClassName('yy-lIST')[0]
                item.appointDatas.forEach((appItem, appIndex) => {
                    let listGroupItem = document.createElement('li')
                    listGroupItem.className = 'list-group-item bg-transparent text-start text-white'
                    listGroupItem.innerText = appItem.name + '*' + appItem.project
                    listGroup.appendChild(listGroupItem)
                })

            }
        }
        afternoonBox.appendChild(element)
    })
    //     记录点击的下标和时间段
    let timeout = {
        index: null,
        time: null
    }
    let actionData = null
    const appoint = document.getElementsByClassName('appoint')
    for (const appointElement of appoint) {
        appointElement.addEventListener('click', () => {
            timeout.index = appointElement.getAttribute('data-index')
            timeout.time = appointElement.getAttribute('data-time')
            // 获取提交的所需的时间节点
            if (timeout.time === 'morning') {
                actionData = morning[timeout.index]
            } else if (timeout.time === 'afternoon') {
                actionData = afternoon[timeout.index]
            }
        })
    }
</script>
</body>

</html>